package client.GUI;

import client.backend.Connection;

import client.GUI.dashboard.DashboardPanel;
import client.GUI.dashboard.PricesPanel;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Color;

public class BottomPanel extends JPanel implements ActionListener{
		
	private JButton logOut;
	private JButton quit;
	private JButton refreshTables;
	
	/**
	 * This is the default constructor
	 */
	public BottomPanel() {
		super();
		initialize();
	}

	/**
	 * This method initialises this
	 * 
	 * @return void
	 */
	private void initialize() {
		logOut = new JButton("Log Out");
		quit = new JButton("Quit");
		refreshTables = new JButton("Refresh Tables");
		
		
		logOut.setBounds(10, 10, 80, 30);
		quit.setBounds(934, 10, 80, 30);
		refreshTables.setBounds(100, 10, 200, 30);
		
		this.setSize(1024, 50);
		this.setLayout(null);
		
		this.add(logOut);
		this.add(refreshTables);
		this.add(quit);
		
		this.setBackground(Color.black);
		
		quit.addActionListener(this);
		logOut.addActionListener(this);
		refreshTables.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == quit) {
			Connection.getInstance().quit();
			PricesPanel.getInstance().setStop(true);
		}
		else if (e.getSource() == logOut) {
			if (Connection.getInstance().logout()) {
				GUIClient.getInstance().displayLogin();
				PricesPanel.getInstance().setStop(true);
			}
		}
		else if (e.getSource() == refreshTables) {
			DashboardPanel.getInstance().refreshTables();
		}
	}
}  //  @jve:decl-index=0:visual-constraint="82,5"



